package com.liyunc.demo.detect.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.Objects;

@Slf4j
public class Resources {

    /**
     * 获取资源文件的绝对路径.
     *
     * @param path 相对路径
     */
    public static String getResourceAbsolutePath(String path) {
        if (null != path) {
            String tempPath =
                    Objects.requireNonNull(Resources.class.getClassLoader().getResource(path))
                            .getFile();
            if (null != tempPath) {
                File file = new File(tempPath);
                return file.getAbsolutePath();
            } else {
                log.info("couldn't find file:[{}]", path);
            }
        }
        return null;
    }


    public static void main(String[] args) {
        System.out.println(getResourceAbsolutePath("data/haarcascade_frontalface_alt.xml"));
        System.out.println(getResourceAbsolutePath("data/faceRecognizer.xml"));
    }
}
